
//继承和多态

class Animal{
    public String name;
    public int age;
    public String color;
    //构造方法
    public Animal(){
    }
    public Animal(String name,int age,String color){
        this.name = name;
        this.age = age;
        this.color = color;
    }
    public void eat(){
        System.out.println(name + "正在吃饭");
    }
}
class Cat extends Animal{
    public Cat(){
        //不写默认有一个super()
        super();
    }
    public Cat(String name,int age,String color){
        //先父类部分初始化
        super(name, age, color);
    }
    @Override //检查重写名是否一致
    public void eat(){
        System.out.println(name + "正在吃猫粮");
    }
    public void cheatMouse(){
        System.out.println(name + "正在抓老鼠");
    }
}

class Dog extends Animal{
    public boolean silly;
    public Dog(){
        super();
    }
    public Dog(String name,int age,String color,boolean silly){
        //先父类部分初始化
        super(name, age, color);
        this.silly = silly;
    }
    @Override
    public void eat(){
        System.out.println(name + "正在吃狗粮");
    }
    public void weat(){
        System.out.println(name + "正在摇尾巴");
    }
}
public class Test {
    public static void main(String[] args) {
        Dog dog = new Dog("小黑",5,"red",false);
        dog.eat();
        dog.weat();
        //向上转型 + 多态
        Animal animal = new Cat("咪咪",2,"bule");
        animal.eat();
        Animal animal1 = new Dog("旺财",5,"red",false);
        animal1.eat();
    }
}
